package com.yd.app.mapper.provider;

import com.yd.domain.searchParam.GTypeOneParam;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author: zy
 * @Desc: 商品一级类型
 * @Date:  2018/5/2
 * @Param
 */
public class GTypeOneProvider extends BaseProvider{
    /**
     * @Author: zy
     * @Desc: 分页查询数据
     * @Date:  2018/3/9
     * @Param
     */
    public String searchGTypeOneList(Map map){
        GTypeOneParam gTypeOneParam= (GTypeOneParam) map.get("gTypeOneParam");
        StringBuilder sb=new StringBuilder("select *  FROM business_gtype_one o " +
                " WHERE 1=1 ");
        sb.append(createSearchSanWhereSql(gTypeOneParam));
        sb.append("  limit #{startRow},#{pageSize}");
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:查询数据条数
     * @Date:  2018/5/2
     */
    public String searchGTypeOneCount(Map map){
        GTypeOneParam gTypeOneParam= (GTypeOneParam) map.get("gTypeOneParam");
        StringBuilder sb=new StringBuilder("SELECT COUNT(1) from business_gtype_one o  " +
                "  where 1=1 ");
        sb.append(createSearchSanWhereSql(gTypeOneParam));
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:查询条件
     * @Date:  2018/5/2
     */
    private String createSearchSanWhereSql(GTypeOneParam gTypeOneParam){
        StringBuilder sb=new StringBuilder();
        if(!StringUtils.isEmpty(gTypeOneParam.getTitle())){
            sb.append(" and o.title like  '%"+gTypeOneParam.getTitle()+"%'  ");
        }
        return sb.toString();
    }

}
